<% add_decidim_page_title(t("decidim.forms.admin.questionnaires.edit.title")) %>

<% if templates_defined? && choose_template? %>
  <%= render partial: "decidim/templates/admin/questionnaire_templates/choose", locals: { target: questionnaire, form_title: t("decidim.forms.admin.questionnaires.edit.title"), show_buttons: true } %>
<% else %>

<div class="questionnaire-questions">
  <div class="item_show__header">
    <h1 class="item_show__header-title">
      <%= t("decidim.forms.admin.questionnaires.edit_questions.title") %>

      <% unless template? questionnaire.questionnaire_for %>
        <% if questionnaire.questions_editable? %>
          <button class="button button__sm button__transparent-secondary add-question"><%= t(".add_question") %></button>
          <button class="button button__sm button__transparent-secondary add-separator"><%= t(".add_separator") %></button>
          <button class="button button__sm button__transparent-secondary add-title-and-description"><%= t(".add_title_and_description") %></button>
        <% end %>
        <% if allowed_to? :preview, :questionnaire %>
          <%= link_to t("preview", scope: "decidim.forms.admin.questionnaires.form"), public_url, class: "button button__sm button__transparent-secondary", target: :_blank, data: { "external-link": false } %>
        <% end %>
        <% if questionnaire.responses.any? %>
          <%= export_dropdown(current_component, questionnaire.id) if allowed_to? :export_responses, :questionnaire %>
          <% if allowed_to? :show, :questionnaire_responses %>
            <%= link_to t("actions.show", scope: "decidim.forms.admin.questionnaires"), questionnaire_participants_url, class: "button button__sm button__secondary new whitespace-nowrap" %>
          <% end %>
        <% else %>
          <button class="button button__sm button__secondary whitespace-nowrap" disabled><%= t("empty", scope: "decidim.forms.admin.questionnaires.responses") %></button>
        <% end %>
      <% end %>
    </h1>
  </div>
</div>

<div class="item__edit item__edit-1col">
  <div class="item__edit-form">
    <%= decidim_form_for(@form, url: update_url, method: :put, html: { class: "form-defaults form edit_questionnaire" }) do |form| %>
      <%= render partial: "decidim/forms/admin/questionnaires/questions_form", object: form %>
      <div class="item__edit-sticky">
        <div class="item__edit-sticky-container">
          <%= form.submit t(".save"), class: "button button__sm button__secondary" %>
        </div>
      </div>
    <% end %>
  </div>
</div>

<% end %>
